<template>
	<view class="proxy-account-info">
		<view class="base-info-pane">
			<view class="info-avatar-wrapper">
				<image :src="userInfo.face" class="info-avatar" mode="aspectFill"></image>
			</view>
			<view class="info-content-wrapper">
				<view class="user-name">
					{{userName}}
				</view>
				<view class="alliance-code">
					合作方编号: {{unionId}}
				</view>
			</view>
			<view class="info-more-btn-wrapper" @tap="doJump('userInfo/userInfo')">
				<tui-icon name="arrowright" :size="32" color="#FFF"></tui-icon>
			</view>
		</view>
		<view class="account-body">
			<view class="banlance-pane">
				<view class="banlance-info the-left">
					<view class="banlance-price">
						{{balance}}
					</view>
					<view class="banlace-txt">
						帐户
					</view>
				</view>
				<view class="banlance-info disabled">
					<view class="operator-btn">
						已绑定 >
					</view>
					<view class="banlace-txt">
						我的银行卡
					</view>
				</view>
			</view>
			<tui-list-cell padding="0" :lineLeft="false" :arrow="true" @tap="doJump('withdraw/withdraw', { balance })">
				<view class="tui-list-cell">
					<image src="https://cwmall.oss-cn-shanghai.aliyuncs.com/mp-icon/proxy/cash-out.png" class="cell-icon" mode="aspectFill"></image>
					提现
				</view>
			</tui-list-cell>
			<tui-list-cell padding="0" :lineLeft="false" :arrow="true" @tap="doJump('withdrawRecord/withdrawRecord')">
				<view class="tui-list-cell">
					<image src="https://cwmall.oss-cn-shanghai.aliyuncs.com/mp-icon/proxy/cash-out-list.png" class="cell-icon" mode="aspectFill"></image>
					提现记录
				</view>
			</tui-list-cell>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: this.$store.state.USER,
				balance: '0.00'
			};
		},
		computed: {
			userName() {
				const { username } = this.userInfo
				return username.substr(0, 1) + new Array(username.length - 1).fill('*').join('')
			},
			unionId() {
				return this.$store.state.customerId
			}
		},
		mounted() {
			this.getBalance()
		},
		methods: {
			async getBalance() {
				const { success, data } = await this.$api.getAccountBalance()
				if (success && data) {
					this.balance = data.curBala.toFixed(2)
				} 
			},
			doJump(path, params) {
				const queryStr = []
				if (params) {
					for(const key in params) {
						queryStr.push(`${key}=${params[key]}`)
					}
				}
				uni.navigateTo({
					url: `/pagesA/${path}${queryStr.length ? '?' + queryStr.join('&') : ''}`
				})
			}
		}
	}
</script>

<style lang="scss">
page {
	background: #FFF;
}
.proxy-account-info {
	.base-info-pane {
		background-color: #e41f19;
		padding: 40rpx 30rpx 60rpx 60rpx;
		display: flex;
		flex-wrap: nowrap;
		
		.info-avatar-wrapper {
			width: 120rpx;
			height: 120rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			border-radius: 12rpx;
			background: #eee;
			margin-right: 50rpx;
			overflow:hidden;
			.info-avatar {
				width: 120rpx;
				height: 120rpx;
			}
		}
		
		.info-content-wrapper {
			flex: 1;
			color: #fff;
			display: flex;
			flex-direction: column;
			
			.user-name {
				font-size: 50rpx;
				font-weight: bold;
			}
			.alliance-code {
				font-size: 32rpx;
			}
		}
		
		.info-more-btn-wrapper {
			width: 80rpx;
			display: flex;
			align-items: center;
			justify-content: flex-end;
		}
	}
	.account-body {
		padding: 0 30rpx;
		.banlance-pane {
			display: flex;
			padding: 30rpx 0 50rpx;
			border-bottom: 1px solid #eee;
			.banlance-info {
				flex: 1;
				&.the-left {
					border-right: 1px solid #eee;
				}
				.banlance-price {
					text-align: center;
					font-weight: bold;
					font-size: 40rpx;
					height: 60rpx;
				}
				.operator-btn {
					text-align: center;
					height: 60rpx;
					line-height: 60rpx;
				}
				.banlace-txt {
					text-align: center;
					font-size: 28rpx;
				}
				&.disabled {
					color: #b1b1b1;
				}
			}
		}
		.tui-list-cell {
			display: flex;
			align-items: center;
			padding: 24rpx 30rpx;
			font-size: 30rpx;
			.cell-icon {
				width: 50rpx;
				height: 50rpx;
				margin-right: 26rpx;
			}
		}
	}
	
}
</style>
